package com.atguigu.gmallsuger.mapper;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface KeywordStatsMapper {
    
    @Select(
        "select " +
            " keyword, " +
            " sum(ct * multiIf(" +
            "                   source='SEARCH', 10, " +
            "                   source='ORDER', 8, " +
            "                   source='CART', 5, " +
            "                   source='CLICK', 3, " +
            "                 0)" +
            "    ) score " +
            "from keyword_stats_2021 " +
            "where toYYYYMMDD(stt)=#{date} " +
            "group by keyword " +
            "order by score desc " +
            "limit #{limit}"
    )
    List<JSONObject> getKewWordStats(@Param("date") int date,
                                     @Param("limit") int limit);
    
}
